var Adv_skd=require("./Adv_skd")

var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s = e("ListView"),
    c = e("Util"),
    l = (e("ConfigGameData"), e("GameData")),
    d = e("LoginProxy"),
    u = e("RankProxy"),
    p = e("RankProxy2"),
    h = e("SkinLevelData"),
    f = cc._decorator,
    _ = f.ccclass,
    y = f.property,
    m = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.content = null),
                (t.ItemsParent = null),
                (t.btn_start = null),
                (t.isRunAni = !1),
                (t.btn_endless = null),
                (t.btn_TimeLimit = null),
                (t.userDataItem = null),
                (t.listView = null),
                (t.select_endless = !0),
                (t.UI_Select = null),
                (t.UI_SelectNo = null),
                (t.rankList = null),
                t
            );
        }
        return (
            a(t, e),
            (t.prototype.onResetView = function () {
                e.prototype.onResetView.call(this),
                    ad.curr_platform == window.ad.Platform.MEI_ZU
                        ? ad.adInterface.showInterstitial()
                        : ad.curr_platform == window.ad.Platform.HUAWEI_GAME
                            ? ad.adInterface.showNativeInterstitial()
                            : ad.curr_platform == window.ad.Platform.BAI_DU && ad.adInterface.showBanner(),
                    this.init();

                Adv_skd.default.instance.hideAllAdv();
                Adv_skd.default.instance.showGridAdRight();
            }),
            (t.prototype.onClickClose = function () {
                Adv_skd.default.instance.hideAllAdv();

                Adv_skd.default.instance.showGridAdLeftOne();
                Adv_skd.default.instance.showGridAdRightOne();
                Adv_skd.default.instance.showInterstitialAd();

                game.AudioManager.playBtnEffect(), this.closeView(!0);
            }),
            (t.prototype.onDisable = function () {
                ad.curr_platform == window.ad.Platform.BAI_DU && ad.adInterface.hideBanner(!1);
            }),
            (t.prototype.onEnable = function () {
                cc.SDK.showGetUICoinBox(
                    function (e) {
                        var t = l.default.instance.getPlayerCoin();
                        l.default.instance.setPlayerCoin(t + e);
                    },
                    function () {},
                    cc.SDK.gameID
                );
            }),
            (t.prototype.registerMediator = function () {
                e.prototype.registerMediator.call(this);
            }),
            (t.prototype.removeMediator = function () {
                e.prototype.removeMediator.call(this);
            }),
            (t.prototype.addEvent = function () {
                e.prototype.addEvent.call(this),
                    this.btn_endless.on(game.EngineEventType.NodeEvent.click, this.onClickbtn_endless, this),
                    this.btn_TimeLimit.on(game.EngineEventType.NodeEvent.click, this.onClickbtn_TimeLimit, this),
                    game.appFacade.view.registerObserver(
                        u.default.RANK_LIST_UPDATR,
                        new puremvc.Observer(this.onRankListView1, this)
                    ),
                    game.appFacade.view.registerObserver(
                        p.default.RANK_LIST_UPDATR,
                        new puremvc.Observer(this.onRankListView2, this)
                    );
            }),
            (t.prototype.removeEvent = function () {
                e.prototype.removeEvent.call(this),
                    this.btn_endless.off(game.EngineEventType.NodeEvent.click, this.onClickbtn_endless, this),
                    this.btn_TimeLimit.off(game.EngineEventType.NodeEvent.click, this.onClickbtn_TimeLimit, this),
                    game.appFacade.view.removeObserver(u.default.RANK_LIST_UPDATR, this),
                    game.appFacade.view.removeObserver(p.default.RANK_LIST_UPDATR, this);
            }),
            (t.prototype.onClickStartRun = function () {
                this.isRunAni || (this.isRunAni = !0);
            }),
            (t.prototype.onLoad = function () {
                this.isCache = !1;
            }),
            (t.prototype.init = function () {
                (this.content = this.node.getChildByName("content")),
                    (this.UI_Select = this.btn_endless.getComponent(cc.Sprite).spriteFrame),
                    (this.UI_SelectNo = this.btn_TimeLimit.getComponent(cc.Sprite).spriteFrame),
                    this.refresh_btn();
                var e = game.appFacade.retrieveProxy(u.default.NAME);
                e.requestRankList(), e.requestSelfRank();
                var t = game.appFacade.retrieveProxy(p.default.NAME);
                t.requestRankList(), t.requestSelfRank();
            }),
            (t.prototype.onClickbtn_endless = function () {
                this.select_endless || ((this.select_endless = !0), this.refresh_btn());
            }),
            (t.prototype.onClickbtn_TimeLimit = function () {
                this.select_endless && ((this.select_endless = !1), this.refresh_btn());
            }),
            (t.prototype.refresh_btn = function () {
                this.select_endless
                    ? ((this.btn_endless.getComponent(cc.Sprite).spriteFrame = this.UI_Select),
                      (this.btn_TimeLimit.getComponent(cc.Sprite).spriteFrame = this.UI_SelectNo))
                    : ((this.btn_endless.getComponent(cc.Sprite).spriteFrame = this.UI_SelectNo),
                      (this.btn_TimeLimit.getComponent(cc.Sprite).spriteFrame = this.UI_Select)),
                    this.onRankListUpde();
            }),
            (t.prototype.onRankListView1 = function () {
                this.select_endless && this.onRankListUpde();
            }),
            (t.prototype.onRankListView2 = function () {
                this.select_endless || this.onRankListUpde();
            }),
            (t.prototype.onRankListUpde = function () {
                var e;
                (e = this.select_endless
                    ? game.appFacade.retrieveProxy(u.default.NAME).rankVO.rankList
                    : game.appFacade.retrieveProxy(p.default.NAME).rankVO.rankList),
                    (this.rankList = e),
                    this.listView.refreshHandler(this.rankList.length - 3, this.onListRender, this);
                for (var t = this.content.getChildByName("bg").getChildByName("items"), o = 0; o < 3; o++) {
                    var n = t.children[o];
                    o >= this.rankList.length ? (n.active = !1) : ((n.active = !0), this.onListRender(n, null, o - 3));
                }
                this.refreshUserData();
            }),
            (t.prototype.onListRender = function (e, t, o) {
                var n = this.rankList[o + 3];
                e.getChildByName("item_bg") && (e.getChildByName("item_bg").active = o % 2 == 1),
                    e.getChildByName("item_index") &&
                        (e.getChildByName("item_index").getComponent(cc.Label).string = "" + (o + 3 + 1));
                var i = c.default.parseObject(n.extendParams);
                (e.getChildByName("label_name").getComponent(cc.Label).string = i.nickName + ""),
                    (e.getChildByName("label_fraction").getComponent(cc.Label).string = n.weight + "");
                var a = e.getChildByName("mask").getChildByName("user_image");
                cc.assetManager.loadBundle("popup", function (e, t) {
                    e ||
                        t.load(i.avatarUrl, cc.SpriteFrame, function (e, t) {
                            e || (a.getComponent(cc.Sprite).spriteFrame = t);
                        });
                });
            }),
            (t.prototype.refreshUserData = function () {
                (this.userDataItem.getChildByName("label_name").getComponent(cc.Label).string =
                    l.default.instance.UserName),
                    game.appFacade.retrieveProxy(d.default.NAME).loginVO.userInfo;
                var e,
                    t = this.userDataItem.getChildByName("mask").getChildByName("user_image");
                cc.assetManager.loadBundle("popup", function (e, o) {
                    if (!e) {
                        var n = l.default.instance.getUserSkin(),
                            i = h.SkinLevelData.instance.skinList[n];
                        o.load("textures/EggView/skin_icon/" + i.name, cc.SpriteFrame, function (e, o) {
                            if (e)
                                return (
                                    console.log("加载头像出错：", "textures/EggView/skin_icon/" + i.name),
                                    void cc.error(e.message || e)
                                );
                            t.getComponent(cc.Sprite).spriteFrame = o;
                        });
                    }
                });
                for (var o = 0; o < this.rankList.length; o++) {
                    var n = this.rankList[o];
                    if (c.default.parseObject(n.extendParams).nickName == l.default.instance.UserName)
                        return (
                            (this.userDataItem.getChildByName("item_index").getComponent(cc.Label).string = o + 1 + ""),
                            void (this.userDataItem.getChildByName("label_fraction").getComponent(cc.Label).string =
                                n.weight + "")
                        );
                }
                (this.userDataItem.getChildByName("item_index").getComponent(cc.Label).string = "101"),
                    (e = this.select_endless
                        ? Number(c.default.getItem("HighestScoreInHistory_endless", "0"))
                        : Number(c.default.getItem("HighestScoreInHistory_TimeLimit", "0"))),
                    (this.userDataItem.getChildByName("label_fraction").getComponent(cc.Label).string = e + "");
            }),
            r([y(cc.Node)], t.prototype, "btn_endless", void 0),
            r([y(cc.Node)], t.prototype, "btn_TimeLimit", void 0),
            r([y(cc.Node)], t.prototype, "userDataItem", void 0),
            r([y(s.default)], t.prototype, "listView", void 0),
            r([_], t)
        );
    })(game.BasePopView);
i.default = m;
